<!doctype html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>注册</title>

    <link rel="stylesheet" href="{:C('__STATIC__')}{$theme}/Static/{:C('css')}/login.css" />
    <link rel="stylesheet" href="{:C('__STATIC__')}{$theme}/Static/{:C('css')}/common.css" />
    <script type="text/javascript" src="__PUBLIC__/Admin/lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript">
        function resize() {
            var clientWidth = document.documentElement.clientWidth;
            document.documentElement.style.fontSize = 100 * (clientWidth / 750) + 'px';
        }
        resize();
        window.addEventListener('resize', resize);
    </script>
</head>
<body>
    <div class="banx-a">
        <img src="{:C('__STATIC__')}{$theme}/Static/img/login.png" class="logo">
        <form action="" method="post" id="register">
            <input type="number" id="mobile" placeholder="请输入手机号" class="inp1" maxlength="11"/>
            <if condition="$open_code eq 1">
                <div class="yanzheng">
                    <input type="text" id="code" placeholder="验证码"/>
                    <input type="button" value="获取验证码" id="sendSms" for="0"/>
                </div>
            </if>
            <input type="password" id="password" placeholder="请输入密码" class="inp1"/>
            <input type="password" id="newpwd" placeholder="请确认密码" class="inp1"/>
            <input type="number" id="reg_code" placeholder="请输入注册码" class="inp1"/>
            <p>
                <input class="wdt" type="checkbox" <if condition="$agmt eq 1">checked</if> value="1"/>
                同意<a href="{:U('User/agreement',array('shop_id' =>$shop_id))}">用户协议、服务协议</a>
            </p>
            <button type="button" class="inp1 inp3" id="save">注册</button>
            <p class="to_login">已有账号<a href="{:U('Login/index',array('shop_id' => $shop_id))}">直接登陆</a></p>
        </form>
    </div>

    <link rel="stylesheet" href="{:C('__STATIC__')}{$theme}/Static/{:C('css')}/zhuce.css" />
    <script type="text/javascript">
        $(function () {
            //点击发送短信
            var phl = /^0?1[3|4|5|8|7|9][0-9]\d{8}$/;
            var clock = "";
            var open_code = "{$open_code}";
            $('#sendSms').click(function () {
                var ff = $(this).attr("for");
                if(ff == 1){
                    return false;
                }
                var phone = $("#mobile").val();
                if(!(phl.test(phone))) {
                    layer.msg('手机号码格式不正确！', {time:1500});
                } else {
                    $.ajax({
                        type: 'post',
                        url: "{:U('User/sms')}",
                        data: {
                            phone: $("input[name='phone']").val()
                        },
                        success: function (msg) {
                            if(msg.status == 1){
                                layer.msg('短信发送成功', {time:1000});
                                clock = setInterval(GetRunTime ,1000);
                            }else{
                                layer.msg(msg.msg , {time:1500});
                            }
                        }
                    });
                }
            });

            //点击注册
            $('#save').click(function () {
                var mobile = $("#mobile").val();
                var password = $("#password").val();
                var newpwd = $("#newpwd").val();
                var code = $("#code").val();
                var reg_code = $("#reg_code").val();
                var wdt = $(".wdt:checked").val();

                if(!mobile || !phl.test(mobile)){
                    layer.msg("手机号填写有误",{time: 1500});
                    $("#mobile").focus();
                    return false;
                }
                if(!password){
                    layer.msg("请填写密码",{time: 1500});
                    $("#password").focus();
                    return false;
                }
                if(password != newpwd){
                    layer.msg("两次密码不一致",{time: 1500});
                    return false;
                }
                if(open_code == 1 && !code){
                    layer.msg("请填写验证码",{time: 1500});
                    $("#code").focus();
                    return false;
                }

                if(!wdt){
                    layer.msg("请勾选用户协议",{time: 1500});
                    return false;
                }
                $.ajax({
                    type: 'post',
                    url: "{:U('User/register')}",
                    data: {
                        phone: mobile,password: password,newpwd: newpwd,
                        code: code,reg_code: reg_code,shop_id :"{$shop_id}"
                    },
                    beforeSend: function () {
                        layer.msg('提交中', {time:500});
                    },
                    success: function (msg) {
                        if (msg) {
                            if(msg.status == "success"){
                                layer.msg('注册成功',{time: 1500});
                                setTimeout(function(){
                                    window.location.href = "{:U('Login/index', array('shop_id'=>$shop_id))}";
                                },1500);
                            }else{
                                layer.msg(msg.msg,{time: 1500});
                            }
                        } else {
                            layer.msg('注册失败',{time: 1500});
                        }
                    }
                });
            });

            var second = 60;
            function GetRunTime()
            {
                if(second > 0){
                    second -= 1;
                    $("#sendSms").val(second + "S后重新获取");
                    $("#sendSms").attr("for" ,"1");
                    $("#sendSms").css("background" ,"#ccc");
                }else{
                    second = 60;
                    clearInterval(clock);
                    $("#sendSms").val("重新获取");
                    $("#sendSms").attr("for" ,"0");
                    $("#sendSms").css("background" ,"#61cf9f");
                }
            }
        });
    </script>
    <script type="text/javascript" src="__PUBLIC__/Admin/lib/layer/2.4/layer.js"></script>
</body>
</html>